package top.xia17.plugins.fast.auth.security;

import top.xia17.plugins.fast.common.autoconfiguration.TokenProperties;
import top.xia17.plugins.fast.common.security.token.TokenFilter;
import top.xia17.plugins.fast.common.security.token.provider.TokenProvider;
import lombok.RequiredArgsConstructor;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * token的security配置
 *
 * @author xia17
 * @date 2022/2/21
 */
@RequiredArgsConstructor
public class TokenSecurityConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    private final TokenProvider tokenProvider;
    private final TokenProperties tokenProperties;


    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.addFilterBefore(new TokenFilter(tokenProvider, tokenProperties), UsernamePasswordAuthenticationFilter.class);
    }
}
